import Vue from 'vue';
import Vuex from './vuex';

Vue.use(Vuex);
export default new Vuex.Store({
  modules: {
    a: {
      state: {
        x: 1
      },
      modules: {
        c: {
          state: {
            z: 3
          }
        }
      }
    },
    b: {
      state: {
        y: 2
      }
    }
  },
  state: {
    age: 10
  },
  getters: {
    getAge(state) {
      return state.age + 10;
    }
  },
  mutations: {
    addAge(state, age) {
      state.age += age;
    },
    reduceAge(state, age) {
      state.age -= age;
    }
  },
  actions: {
    asyncReduce({commit}, payload) {
      setTimeout(() => {
        // 直接调用，this指向window，store.commit就没有这个问题
        commit('reduceAge', payload);
      }, 100);
    }
  }
});